package com.peak.distribution.entity.order;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

import com.peak.distribution.enums.Constants;
import com.peak.distribution.enums.OrderStatus;
import com.peak.spring.boot.api.entity.DefaultStategyEntity;
import com.peak.spring.boot.tools.Dates;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "dis_order_status_log")
@Data
@EqualsAndHashCode(callSuper=true)
public class DisOrderStatusLog extends DefaultStategyEntity {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;
	
	/** 订单时间 */
	private Date orderTime;
	
	/** 订单状态 */
	private OrderStatus orderStatus;
	
	/** 订单 */
	private DisOrder order;

	@ManyToOne
	@JoinColumn(name = "order_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisOrder getOrder() {
		return order;
	}

	@Enumerated(EnumType.STRING)
	public OrderStatus getOrderStatus() {
		return orderStatus;
	}

	public DisOrderStatusLog(OrderStatus orderStatus, DisOrder order) {
		super();
		this.orderTime = Dates.now();
		this.orderStatus = orderStatus;
		this.order = order;
	}
	
	public DisOrderStatusLog(DisOrder order) {
		super();
		this.orderTime = Dates.now();
		this.orderStatus = order.getStatus();
		this.order = order;
	}

	public DisOrderStatusLog() {
		super();
	}
}
